package com.liang.mianshiweb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBC {
	public void fun1() throws ClassNotFoundException, SQLException {
		//JDBC连接的四大参数
		String driverClassName="com.mysql.jdbc.Driver";String url="jdbc://mysql:3306/shiro";
		String username="root";String password="123";
		
		//注册驱动获得连接对象
		Class.forName(driverClassName);
		Connection con = DriverManager.getConnection(url,username,password);
		
		String sql="insert into user(username,password) values(?,?)";
		String sql1="update user set username=?,password=? where id=?";
		String sql2="delete from user where id=?";
		String sql3="select * from user";
		PreparedStatement psmt = con.prepareStatement(sql);
		psmt.setString(1, "名字");psmt.setString(2, "密码");
		psmt.executeUpdate();
		ResultSet rs = psmt.executeQuery(sql3);
		while(rs.next()) {
			System.out.println(rs.getString(1)+","+rs.getString("password"));
		}
		rs.close();psmt.close();con.close();
	}
}
